package com.br.app.gae.bean;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceException;

import org.springframework.orm.jpa.LocalEntityManagerFactoryBean;

public class SingletonEntityManagerFactory extends
		LocalEntityManagerFactoryBean {

	private static Map<String, EntityManagerFactory> entityManagerFactoryMap = new HashMap<String, EntityManagerFactory>();

	@Override
	protected EntityManagerFactory createNativeEntityManagerFactory()
			throws PersistenceException {
		EntityManagerFactory emf = entityManagerFactoryMap
				.get(getPersistenceUnitName());

		if (emf == null) {
			emf = super.createNativeEntityManagerFactory();
			entityManagerFactoryMap.put(getPersistenceUnitName(), emf);
		}

		return emf;
	}

}